package com.zcl.javaClassAndObject.exception;

/**
 * @Description:
 * @author: zcl
 * @date: 2021/12/14  11:51
 */

class MyException extends Exception {
    public MyException() {
    }

    public MyException(String msg) {
        super(msg);
    }
}


public class InheritingException {
    public static void f() throws MyException {
        System.out.println("Throwing MyException from f()");
        throw new MyException();
    }

    public static void g() throws MyException {
        System.out.println("Throwing MyException from g()");
        throw new MyException("Originated in g()");
    }

    public static void main(String[] args) {
        try {
            f();
        } catch (MyException e) {
            e.printStackTrace();
        }
        try {
            g();
        } catch (MyException e) {
            e.printStackTrace();
        }
    }
}
/**
 * Throwing MyException from f()
 * Throwing MyException from g()
 * com.zcl.javaClassAndObject.exception.MyException
 * 	at com.zcl.javaClassAndObject.exception.InheritingException.f(InheritingException.java:23)
 * 	at com.zcl.javaClassAndObject.exception.InheritingException.main(InheritingException.java:34)
 * com.zcl.javaClassAndObject.exception.MyException: Originated in g()
 * 	at com.zcl.javaClassAndObject.exception.InheritingException.g(InheritingException.java:29)
 * 	at com.zcl.javaClassAndObject.exception.InheritingException.main(InheritingException.java:39)
 * */